package com.jinyu.jyly.ui.mall.detail;

import android.app.Activity;

import com.jinyu.jyly.base.BasePresenter;
import com.jinyu.jyly.bean.AllInfoBean;
import com.jinyu.jyly.net.DataManager;

import rx.Subscription;
import rx.functions.Action1;

public class MallDetailPresenter extends BasePresenter<MallDetailContract.View> implements MallDetailContract.Presenter {

    public MallDetailPresenter(Activity activity, MallDetailContract.View view) {
        super(activity, view);

    }
    /**
     * 获取商品详情
     * @param param
     */
    @Override
    public void getMallDetail(String param) {
        Subscription subscribe = DataManager.getInstance().getGoodsDetail(param)
                .subscribe(new Action1<AllInfoBean>() {
                    @Override
                    public void call(AllInfoBean InfoData) {
                        if (InfoData != null) {
                            mView.onMallDetail(InfoData);
                        }
                    }
                }, new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        handleError(throwable);
                        throwable.printStackTrace();
                        mView.onFailer(throwable);
                    }
                });
        addSubscribe(subscribe);
    }

    /**
     * 提交订单
     * @param param
     */
    @Override
    public void addOrder(String param) {
        Subscription subscribe = DataManager.getInstance().addOrder(param)
                .subscribe(new Action1<AllInfoBean>() {
                    @Override
                    public void call(AllInfoBean InfoData) {
                        if (InfoData != null) {
                            mView.addOrder(InfoData);
                        }
                    }
                }, new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        handleError(throwable);
                        throwable.printStackTrace();
                        mView.onFailer(throwable);
                    }
                });
        addSubscribe(subscribe);
    }


}
